package com.itheima.controller;

import com.itheima.R;
import com.itheima.dto.AddRoleDTO;
import com.itheima.dto.RoleDTO;
import com.itheima.service.SysRoleService;
import com.itheima.vo.RoleInfoVO;
import com.itheima.vo.RolePageVO;
import com.itheima.vo.RoleVO;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/sys_role")
@RequiredArgsConstructor
@RestController
public class RoleController {

    private final SysRoleService sysRoleService;

    /**
     * 分页查询
     * @param page
     * @param limit
     * @param name
     * @return
     */
    @GetMapping("/list")
    public R<RolePageVO> list(Integer page,Integer limit,String name){
        RolePageVO rolePageVO = sysRoleService.list(page,limit,name);
        return R.success(rolePageVO);
    }

    /**
     * 角色列表-全部
     * @return
     */
    @GetMapping("/allData")
    public R<List<RoleVO>> allData(){
        List<RoleVO> roleVOList = sysRoleService.allData();
        return R.success(roleVOList);
    }

    /**
     * 角色添加
     * @param addRoleDTO
     * @return
     */
    @PostMapping("/add")
    public R<?> save(@RequestBody AddRoleDTO addRoleDTO){
        sysRoleService.save(addRoleDTO);
        return R.success();
    }

    /**
     * 查询回显
     * @param id
     * @return
     */
    @GetMapping("/rowInfo")
    public R<RoleInfoVO> rowInfo(String id){
        RoleInfoVO roleInfoVO = sysRoleService.rowInfo(id);
        return R.success(roleInfoVO);
    }

    /**
     * 修改
     * @param roleDTO
     * @return
     */
    @PostMapping("/update")
    public R<?> update(@RequestBody RoleDTO roleDTO){
        sysRoleService.update(roleDTO);
        return R.success();
    }

    /**
     * 根据id删除
     * @param id
     * @return
     */
    @GetMapping("/del")
    public R delete(String id){
        sysRoleService.delete(id);
        return R.success();
    }

}
